﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestingCachedDataProvider
{
	using Mitosoft.Definitions.Data;
	using Mitosoft.TextFileReader;

	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
		}

		private void StartTestButtonClick( object sender, RoutedEventArgs e )
		{
			const uint linePositionsCacheSize = 1024;
			const uint lineContentCacheSize = 1024;

			ICacheableDataBlockProvider<IGenericDataBlockItem<string>, string> _textfileReader =
				new TextFileReader(
					@"K:\projects\Testing\Mitosoft\TestData\LargeFile.txt",
					linePositionsCacheSize,
					lineContentCacheSize
				);

			var cachedBlockDataProvider =
				new CachedBlockDataProvider<IGenericDataBlockItem<string>, string>(
					_textfileReader,
					lineContentCacheSize 
				);

			IEnumerable<IGenericDataBlockItem<string>> values = cachedBlockDataProvider.Values( 0, 3 );

			foreach (IGenericDataBlockItem<string> genericDataBlockItem in values)
			{
				string lineContent = genericDataBlockItem.Value;
			}

			values = cachedBlockDataProvider.Values( 1, 2 );

			foreach( IGenericDataBlockItem<string> genericDataBlockItem in values )
			{
				string lineContent = genericDataBlockItem.Value;
			}
		}
	}
}
